import { Controller, Get, Query } from '@nestjs/common';
import { Users } from '@entities/Users';
import { InjectEntityManager, InjectMikroORM } from '@mikro-orm/nestjs';
import { EntityManager, MikroORM } from '@mikro-orm/mysql';
import { JsonApiResponse } from '@utils/json.api.response';
import { ChatRooms } from '@entities/ChatRooms';
import { knext } from 'knext';
import { OrderJobEnrolls } from '@databases/entities/OrderJobEnrolls';
import { JobTasks } from '@databases/entities/JobTasks';
import { JobProjectJobs } from '@databases/entities/JobProjectJobs';

@Controller('orgnize')
export class OrgnizeController {
    constructor(
        @InjectMikroORM('zp')
        private readonly orm : MikroORM,
        @InjectEntityManager('zp')
        private readonly em : EntityManager 
    ){

    }


    @Get('enroll')
    async enroll()
    {
        let knex = knext(this)

        let res = await knex.fromORM(Users).orderByRaw('RAND()').limit(3)

        return JsonApiResponse.object(res)
        
    }

    @Get('tasks')
    async tasks()
    {
        let knex = knext(this)

        let tasks = await knex.fromORM(JobTasks)
        .selectAll()
        .orderByRaw('RAND()')
        .withEntity(JobProjectJobs,'jobs')
        .limit(3)

        knex.fromORM(OrderJobEnrolls)
        .insert({
            
        })

        return JsonApiResponse.object(res)
        
    }
}